package com.example.customview

import android.content.Context
import android.graphics.BitmapFactory
import android.graphics.Canvas
import android.graphics.Paint
import android.view.View

/**
 * 自定义view
 */
class CustomView: View{

    var bitmapX:Float? = null
    var bitmapY:Float? = null

    constructor(context: Context) : super(context) {
        bitmapX = 290f
        bitmapY = 130f
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        //创建画笔对象
        val paint = Paint()
        val bitmap = BitmapFactory.decodeResource(this.resources, R.mipmap.haha)
        bitmapX?.let { bitmapY?.let { it1 ->
            canvas?.drawBitmap(bitmap, it, it1,paint)
        } }

        //回收图片
        if (bitmap.isRecycled){
            bitmap.recycle()
        }

    }






}